home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / eked-m1.zoo / src / icon.c < prev    next >
C/C++ Source or Header  |  1995-02-19  |  25KB  |  919 lines

  1. /*
  2.  *  EKED-M1 : Editor for Korg M1 synth; icon.c : icon window
  3.  *  Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <stddef.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <gemfast.h>
  24. #include <aesbind.h>
  25. #include <vdibind.h>
  26. #include "gm/gem_man.h"
  27. #include "eked-m1.h"
  28. #include "defs.h"
  29. #include "types.h"
  30. #include "externs.h"
  31.  
  32. #define N_ICONS        12
  33. #define LAST_BANK    9
  34. #define M1        10
  35. #define CARD        11
  36.  
  37. typedef struct {
  38.   BOOL exists;
  39.   OBJECT *icon;
  40.   int x;
  41.   int y;
  42.   BANK *bank;
  43. } ICON;
  44.  
  45. typedef struct {
  46.   enum {
  47.     NO_CHANGE,
  48.     COPY_FOUND,
  49.     COPY_NEEDED,
  50.     SAME_AS
  51.   } type;
  52.   int original;
  53.   int new;
  54. } SLOT;
  55.   
  56. static OBJECT *dialog_enable;
  57. static OBJECT *comb_copy;
  58. static OBJECT *prog_copy;
  59. static OBJECT *bank_copy;
  60. static OBJECT *bank_tx;
  61. static OBJECT *bank_rx;
  62. static OBJECT *bank_print;
  63. static OBJECT *bank_erase;
  64. static OBJECT *bank_flip;
  65. static OBJECT *ceff_copy;
  66. static OBJECT *peff_copy;
  67. static ICON icon_tab[N_ICONS];
  68. static ICON *selected;
  69. static ICON *dest;
  70. static int work_w;
  71. static int work_h;
  72. static int icon_handle;
  73. static int last_bank = -1;
  74.  
  75. static SLOT *track_programs(BYTE *comb, BYTE *dp, BYTE *sp);
  76. static void display(int x_pos, int y_pos, GRECT *clip, long usr_val);
  77. static int action(int handle, E_TYPE type, void *event,
  78.                   int x_pos, int y_pos, long usr_val);
  79. static ICON *find_icon(int x, int y);
  80. static void update_icon(int handle, int x_pos, int y_pos, ICON *t);
  81.  
  82. void ic_init()
  83. {
  84.   int x, y, n, gap_h, bank_w, bank_h;
  85.   OBJECT *icon_form;
  86.  
  87.   rm_gaddr(R_TREE, ICON_FORM, &icon_form);
  88.   rm_gaddr(R_TREE, DIALOG_ENABLE, &dialog_enable);
  89.   rm_gaddr(R_TREE, COMB_COPY, &comb_copy);
  90.   rm_gaddr(R_TREE, PROG_COPY, &prog_copy);
  91.   rm_gaddr(R_TREE, BANK_COPY, &bank_copy);
  92.   rm_gaddr(R_TREE, BANK_TX, &bank_tx);
  93.   rm_gaddr(R_TREE, BANK_RX, &bank_rx);
  94.   rm_gaddr(R_TREE, BANK_PRINT, &bank_print);
  95.   rm_gaddr(R_TREE, BANK_ERASE, &bank_erase);
  96.   rm_gaddr(R_TREE, BANK_FLIP, &bank_flip);
  97.   rm_gaddr(R_TREE, CEFF_COPY, &ceff_copy);
  98.   rm_gaddr(R_TREE, PEFF_COPY, &peff_copy);
  99.  
  100.   icon_tab[M1].icon = icon_form + M1_ICON;
  101.   icon_tab[CARD].icon = icon_form + CARD_ICON;
  102.   icon_form += BANK_ICON;
  103.  
  104.   gap_h = char_h / 2;
  105.   bank_w = icon_form->ob_width + char_w;
  106.   bank_h = icon_form->ob_height + gap_h;
  107.   work_w = char_w + 5 * bank_w;
  108.   work_h = gap_h + 2 * bank_h + icon_tab[CARD].icon->ob_height + gap_h;
  109.  
  110.   icon_tab[M1].exists = TRUE;
  111.   icon_tab[M1].x = char_w;
  112.   icon_tab[M1].y = gap_h + 2 * bank_h;
  113.   icon_tab[CARD].exists = TRUE;
  114.   icon_tab[CARD].x = char_w + icon_tab[M1].icon->ob_width + char_w;
  115.   icon_tab[CARD].y = gap_h + 2 * bank_h;
  116.  
  117.   y = gap_h;
  118.   for(n = 0, x = char_w; n <= 4; n++, x += bank_w){
  119.     icon_tab[n].exists = FALSE;
  120.     icon_tab[n].icon = icon_form;
  121.     icon_tab[n].x = x;
  122.     icon_tab[n].y = y;
  123.   }
  124.   y += bank_h;
  125.   for(n = 5, x = char_w; n <= 9; n++, x += bank_w){
  126.     icon_tab[n].exists = FALSE;
  127.     icon_tab[n].icon = icon_form;
  128.     icon_tab[n].x = x;
  129.     icon_tab[n].y = y;
  130.   }
  131. }
  132.  
  133. void ic_exit()
  134. {
  135.   int i;
  136.  
  137.   for(i = 0; i <= last_bank; i++)
  138.     FREE(icon_tab[i].bank);
  139. }
  140.  
  141. void ic_window()
  142. {
  143.   int t;
  144.  
  145.   t = wm_open(NAME | CLOSER | FULLER | MOVER | SIZER |
  146.               UPARROW | DNARROW | VSLIDE | LFARROW | RTARROW | HSLIDE,
  147.               (GRECT *) 0, "EKED-M1", work_w, work_h, char_w, char_h,
  148.               &display, &action, 0L);
  149.   if(t < 0){
  150.     fm_alert(1, WINDOW_ALERT);
  151.     return;
  152.   }
  153.   icon_handle = t;
  154. }
  155.  
  156. void ic_dialogs()
  157. {
  158.   static struct {
  159.     int name;
  160.     OBJECT **objp;
  161.   } table[] = {
  162.     {DE_BANKCOPY,    &bank_copy},
  163.     {DE_BANKERASE,    &bank_erase},
  164.     {DE_BANKTX,        &bank_tx},
  165.     {DE_BANKRX,        &bank_rx},
  166.     {DE_BANKPRINT,    &bank_print},
  167.     {DE_COMB,        &comb_copy},
  168.     {DE_PROG,        &prog_copy},
  169.     {DE_BANKFLIP,    &bank_flip},
  170.     {DE_CEFF,        &ceff_copy},
  171.     {DE_PEFF,        &peff_copy}
  172.   };
  173.   int i;
  174.  
  175.   for(i = 0; i < 10; i++){
  176.     if((*table[i].objp)->ob_state & DISABLED)
  177.       dialog_enable[table[i].name].ob_state  &= ~SELECTED;
  178.     else
  179.       dialog_enable[table[i].name].ob_state  |= SELECTED;
  180.   }
  181.  
  182.   if(fm_dialog(dialog_enable, 0, NULL, 0) == DE_OK){
  183.     for(i = 0; i < 10; i++){
  184.       if(dialog_enable[table[i].name].ob_state & SELECTED)
  185.         (*table[i].objp)->ob_state &= ~DISABLED;
  186.       else
  187.         (*table[i].objp)->ob_state |= DISABLED;
  188.     }
  189.   }
  190. }
  191.  
  192. void ic_newbank()
  193. {
  194.   ICON *p;
  195.   BANK *bank;
  196.   int x_pos, y_pos;
  197.   long usr_val;
  198.  
  199.   if(last_bank == LAST_BANK){
  200.     fm_alert(1, BANKMAX_ALERT);
  201.     return;
  202.   }
  203.   bank = MALLOC(BANK);
  204.   if(bank == NULL){
  205.     fm_alert(1, BANKMEM_ALERT);
  206.     return;
  207.   }
  208.   memset((char *) bank, 0, sizeof(BANK));
  209.   last_bank++;
  210.   p = icon_tab + last_bank;
  211.   p->bank = bank;
  212.   p->exists = TRUE;
  213.   bank->bank_nr = p - icon_tab;
  214.   bank->glob_win = bank->comb_win = bank->prog_win = 0;
  215.   bank->filename[0] = '\0';
  216.   wm_getdata(icon_handle, &x_pos, &y_pos, &usr_val);
  217.   update_icon(icon_handle, x_pos, y_pos, p);
  218. }
  219.  
  220. void ic_bankop(int op)
  221. {
  222.   BANK *bank;
  223.   int n;
  224.  
  225.   if(!selected)
  226.     return;
  227.   bank = selected->bank;
  228.   if(bank == NULL)
  229.     return;
  230.   n = selected - icon_tab;
  231.   switch(op){
  232.   case M_GLOB_EDIT:
  233.     if(bank->glob_win != 0)
  234.       wm_topped(bank->glob_win);
  235.     else
  236.       ge_window(bank);
  237.     break;
  238.   case M_COMB_LIST:
  239.     if(bank->comb_win != 0)
  240.       wm_topped(bank->comb_win);
  241.     else
  242.       ls_window(COMB_LIST, bank);
  243.     break;
  244.   case M_PROG_LIST:
  245.     if(bank->prog_win != 0)
  246.       wm_topped(bank->prog_win);
  247.     else
  248.       ls_window(PROG_LIST, bank);
  249.     break;
  250.   case M_OPEN:
  251.     load_bank(bank);
  252.     break;
  253.   case M_SAVE_AS:
  254.     save_bank(bank, TRUE);
  255.     break;
  256.   case M_SAVE:
  257.     save_bank(bank, FALSE);
  258.     break;
  259.   case M_PRINT:
  260.     ic_bankprint(n);
  261.     break;
  262.   case M_COPY:
  263.     ic_bankcopy(n, n);
  264.     break;
  265.   case M_FLIP:
  266.     ic_bankflip(n);
  267.     break;
  268.   case M_ERASE:
  269.     ic_bankerase(n);
  270.     break;
  271.   case M_TRANSMIT:
  272.     ic_banktx(FALSE, n);
  273.     break;
  274.   case M_RECEIVE:
  275.     ic_bankrx(n, FALSE);
  276.     break;
  277.   }
  278. }
  279.  
  280. void ic_combcopy(int db, int dc, int sb, int sc)
  281. {
  282.   static int msg[] = {UPDATE_ITEM, 0};
  283.   BYTE *d, *s;
  284.   BOOL redraw_prog;
  285.   int t, i;
  286.   SLOT *link = NULL;
  287.  
  288.   if(!(comb_copy->ob_state & DISABLED)){
  289.     unum1_update(comb_copy + CC_FROM_BANK, sb);
  290.     unum_update(comb_copy + CC_FROM_COMB, sc);
  291.     unum1_update(comb_copy + CC_TO_BANK, db);
  292.     unum_update(comb_copy + CC_TO_COMB, dc);
  293.     fm_begin_dialog(comb_copy, 0);
  294.     do{
  295.       t = fm_run_dialog();
  296.       switch(t){
  297.       case CC_FROM_BANK:
  298.         sb = fm_roll(comb_copy, t, sb, 0, last_bank, &unum1_update);
  299.         break;
  300.       case CC_FROM_COMB:
  301.         sc = fm_roll(comb_copy, t, sc, 0, 99, &unum_update);
  302.         break;
  303.       case CC_TO_BANK:
  304.         db = fm_roll(comb_copy, t, db, 0, last_bank, &unum1_update);
  305.         break;
  306.       case CC_TO_COMB:
  307.         dc = fm_roll(comb_copy, t, dc, 0, 99, &unum_update);
  308.         break;
  309.       }
  310.     }while(t != CC_OK && t != CC_CANCEL);
  311.     fm_end_dialog();
  312.     if(t == CC_CANCEL || (sb == db && sc == dc))
  313.       return;
  314.   }
  315.   d = COMB_DATA(icon_tab[db].bank, dc);
  316.   s = COMB_DATA(icon_tab[sb].bank, sc);
  317.   if((comb_copy[CC_REF].ob_state & SELECTED)
  318.   && (comb_copy[CC_COMB].ob_state & SELECTED)
  319.   && sb != db){
  320.     link = track_programs(s, 
  321.       ic